Move function 'strenquote' from unicsv to common utils.
authoroliskoli <oliskoli>
Fri, 29 Jun 2007 21:01:35 +0000 (21:01 +0000)
committeroliskoli <oliskoli>
Fri, 29 Jun 2007 21:01:35 +0000 (21:01 +0000)
defs.h
util.c

diff --git a/defs.h b/defs.h
index 1dffa3e8f9d89d2ee0127d00fa217ef662e5e2b4..c62d0718b1aeb677cdcaada8a4f2f7271e7abdd5 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -747,6 +747,7 @@ int case_ignore_strcmp(const char *s1, const char *s2);
 int case_ignore_strncmp(const char *s1, const char *s2, int n);
 int str_match(const char *str, const char *match);
 int case_ignore_str_match(const char *str, const char *match);
+char * strenquote(const char *str, const char quot_char);
 
 char *strsub(const char *s, const char *search, const char *replace);
 char *gstrsub(const char *s, const char *search, const char *replace);
diff --git a/util.c b/util.c
index 82630846368eb8c719295da52035565a16d39f5b..51b78cd3bd5268c7800427289a4bef6126b02898 100644 (file)
--- a/util.c
+++ b/util.c
@@ -595,6 +595,33 @@ case_ignore_str_match(const char *str, const char *match)
        return res;
 }
 
+char *
+strenquote(const char *str, const char quot_char)
+{
+       int len;
+       char *cin, *cout;
+       char *tmp;
+
+       if (str == NULL) cin = "";
+       else cin = (char *)str;
+       
+       len = strlen(cin);
+       cout = tmp = xmalloc((len * 2) + 3);
+       
+       *cout++ = quot_char;
+       while (*cin) {
+               *cout++ = *cin;
+               if (*cin++ == quot_char)
+                       *cout++ = quot_char;
+       }
+       *cout++ = quot_char;
+       *cout = '\0';
+       
+       cout = xstrdup(tmp);
+       xfree(tmp);
+       return cout;
+}
+
 void
 printposn(const double c, int is_lat)
 {